package org.testmyapp.application;

import javax.faces.bean.ApplicationScoped;

import javax.inject.Named;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Provides an application context. Up until now only used for injection of TaskWorker Beans
 * @category Provider
 * @see classpath:spring.xml
 * @author neroSieben
 *
 */

@Named
@ApplicationScoped
public class ApplicationContextProvider {

	private ApplicationContext applicationContext;
	
	public Object getBean(String bean) {
		initContext();
		return applicationContext.getBean(bean);
	}

	private void initContext() {
		if(applicationContext == null) {
			applicationContext = new ClassPathXmlApplicationContext("/spring.xml");
		}
	}
	
}
